<template>
  <a-modal
    title="新增光数据"
    :width="900"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    @cancel="handleCancel">

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item
          label="主键id"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback=""
        >
          <a-input placeholder="请输入主键id" v-decorator="['id', {rules: [{required: true, message: '请输入主键id！'}]}]" />
        </a-form-item>

        <a-form-item
          label="标题"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback=""
        >
          <a-input placeholder="请输入标题" v-decorator="['title', {rules: [{required: true, message: '请输入标题！'}]}]" />
        </a-form-item>

        <a-form-item
          label="作者（当前登录用户的账号）"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback=""
        >
          <a-input placeholder="请输入作者（当前登录用户的账号）" v-decorator="['author', {rules: [{required: true, message: '请输入作者（当前登录用户的账号）！'}]}]" />
        </a-form-item>

        <a-form-item
          label="文件大小kb"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback=""
        >
          <a-input placeholder="请输入文件大小kb" v-decorator="['fileSizeKb', {rules: [{required: true, message: '请输入文件大小kb！'}]}]" />
        </a-form-item>

        <a-form-item
          label="分辨率，宽"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback=""
        >
          <a-input placeholder="请输入分辨率，宽" v-decorator="['resolutionWidth', {rules: [{required: true, message: '请输入分辨率，宽！'}]}]" />
        </a-form-item>

        <a-form-item
          label="分辨率，高"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback=""
        >
          <a-input placeholder="请输入分辨率，高" v-decorator="['resolutionHeight', {rules: [{required: true, message: '请输入分辨率，高！'}]}]" />
        </a-form-item>

        <a-form-item
          label="数据来源（值是字典编码）"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback=""
        >
          <a-input placeholder="请输入数据来源（值是字典编码）" v-decorator="['dataSources', {rules: [{required: true, message: '请输入数据来源（值是字典编码）！'}]}]" />
        </a-form-item>

        <a-form-item
          label="备注"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback=""
        >
          <a-input placeholder="请输入备注" v-decorator="['remark', {rules: [{required: true, message: '请输入备注！'}]}]" />
        </a-form-item>

        <a-form-item
          label="头文件的文件id"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback=""
        >
          <a-input placeholder="请输入头文件的文件id" v-decorator="['headerFile', {rules: [{required: true, message: '请输入头文件的文件id！'}]}]" />
        </a-form-item>

        <a-form-item
          label="原始文件的文件id"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback=""
        >
          <a-input placeholder="请输入原始文件的文件id" v-decorator="['originFile', {rules: [{required: true, message: '请输入原始文件的文件id！'}]}]" />
        </a-form-item>

        <a-form-item
          label="可预览文件的文件id"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback=""
        >
          <a-input placeholder="请输入可预览文件的文件id" v-decorator="['previewFile', {rules: [{required: true, message: '请输入可预览文件的文件id！'}]}]" />
        </a-form-item>

        <a-form-item
          label="创建时间"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback=""
        >
          <a-input placeholder="请输入创建时间" v-decorator="['createTime', {rules: [{required: true, message: '请输入创建时间！'}]}]" />
        </a-form-item>

        <a-form-item
          label="创建人"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback=""
        >
          <a-input placeholder="请输入创建人" v-decorator="['createUser', {rules: [{required: true, message: '请输入创建人！'}]}]" />
        </a-form-item>

        <a-form-item
          label="更新时间"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback=""
        >
          <a-input placeholder="请输入更新时间" v-decorator="['updateTime', {rules: [{required: true, message: '请输入更新时间！'}]}]" />
        </a-form-item>

        <a-form-item
          label="更新人"
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          has-feedback=""
        >
          <a-input placeholder="请输入更新人" v-decorator="['updateUser', {rules: [{required: true, message: '请输入更新人！'}]}]" />
        </a-form-item>

      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
  import { add } from '@/api/modular/highlight/highlightManage'

  export default {
    data() {
      return {
        labelCol: {
          xs: {span: 24},
          sm: {span: 5}
        },
        wrapperCol: {
          xs: {span: 24},
          sm: {span: 15}
        },
        visible: false,
        confirmLoading: false,
        form: this.$form.createForm(this)
      }
    },
    methods: {
      add(record) {
        this.visible = true
      },
      handleSubmit() {
        const {form: {validateFields}} = this
        this.confirmLoading = true

        validateFields((errors, values) => {
          if (!errors) {
            add(values).then((res) => {
              this.confirmLoading = false
              if (res.success) {
                this.$message.success('新增成功')
                this.handleCancel()
                this.$emit('ok', values)
              } else {
                this.$message.info('新增失败：' + res.message)
              }
            }).finally((res) => {
              this.confirmLoading = false
            })
          } else {
            this.confirmLoading = false
          }
        })
      },
      handleCancel() {
        this.form.resetFields();
        this.visible = false
      }
    }
  }
</script>
